<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>add_car</title>
<?php
	include("Connection.php");
?>
</head>

<body>

<?php
	$vehicleSno = $_POST['v_sno'];
	$carModel = $_POST['car_model'];
	$carType = $_POST['car_type'];
	$carLocation = $_POST['car_location'];
	$color = $_POST['color'];
	$hourly = $_POST['hourly'];
	$daily = $_POST['daily'];
	$seating = $_POST['seating'];
	$transmission = $_POST['trans_type'];
	$bluetooth = $_POST['b_tooth'];
	$aux = $_POST['aux'];
	
	//Checks to see if a car of the same model is already at the selected location
	//CONSTRAINT: Not allowed to have two cars of the same model at one location
	$carCheck = "SELECT CarModel FROM car WHERE CarModel='$carModel' AND CarLocation='$carLocation';";
	$result = mysql($carCheck);
	
	//no cars of that model at location, add car to location
	if(!mysql_num_rows($result)){
		
		$insertCar = "INSERT INTO car (VehicleSno, AuxiliaryCable, Transmisstion_Type, Seating_Capacity, 			 		                                       BluetoothConnectivity, DailyRate, HourlyRate, Color, Type, CarModel,       		                                       CarLocation)
					  VALUES('$vehicleSno', '$aux', '$transmission', '$seating', '$bluetooth', '$daily', '$hourly',                             '$color', '$carType', '$carModel', '$carLocation');";
		mysql($insertCar);

	}
	else{
		//echo("Car model already at location");
	}
?>
</body>
</html>